package com.easylinkin.linkappapi.grid.controller;

import com.easylinkin.linkappapi.common.model.BaseController;
import com.easylinkin.linkappapi.grid.models.dto.GridReportDayDetailSaveDTO;
import com.easylinkin.linkappapi.grid.models.vo.GridReportDayDetailCollectVO;
import com.easylinkin.linkappapi.grid.service.IGridReportDayDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Setter;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.Arrays;


/**
 * 网格日报填写详情 前端控制器
 *
 * @author kuyujie
 * @since 2024-05-21
 */
@Api(tags = "网格日报填写详情")
@Setter(onMethod_ = @Resource)
@RestController
@RequestMapping("/grid/gridReportDayDetail")
public class GridReportDayDetailController extends BaseController {

    private IGridReportDayDetailService gridReportDayDetailService;

    /**
     * 保存
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "保存", notes = "保存")
    @PostMapping(value = "/save")
    public RestMessage save(@RequestBody GridReportDayDetailSaveDTO dto) {
        this.setOperator(dto);
        gridReportDayDetailService.saveData(dto);
        return RestBuilders.successBuilder().message("保存成功").build();
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @DeleteMapping(value = "/delete")
    public RestMessage delete(@RequestParam("id") Integer id) {
        gridReportDayDetailService.removeById(id);
        return RestBuilders.successBuilder().message("删除成功").build();
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除", notes = "批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public RestMessage deleteBatch(@RequestParam("ids") String ids) {
        this.gridReportDayDetailService.removeByIds(Arrays.asList(ids.split(",")));
        return RestBuilders.successBuilder().message("批量删除成功").build();
    }

    /**
     * 获取日报汇总数据
     */
    @GetMapping(value = "/getDetailCollect")
    public RestMessage getDetailCollect(@RequestParam("reportId") Long reportId) {
        GridReportDayDetailCollectVO data = gridReportDayDetailService.getDetailCollect(reportId);
        return RestBuilders.successBuilder().data(data).build();
    }
}
